package com.fg.cloud.manager.service.agency.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fg.cloud.common.PageUtils;
import com.fg.cloud.common.construction.Select;
import com.fg.cloud.manager.entry.BaseEntity;
import com.fg.cloud.manager.entry.agency.AgencyLevelEntity;
import com.fg.cloud.manager.mapper.BaseMapper;
import com.fg.cloud.manager.mapper.agency.AgencyLevelMapper;
import com.fg.cloud.manager.service.BaseServiceImpl;
import com.fg.cloud.manager.service.agency.AgencyLevelService;

/**
 * 经销商-等级service实现
 * @author around
 * @date 2017-6-21
 */
@Service
public class AgencyLevelServiceImpl extends BaseServiceImpl implements AgencyLevelService {

	@Autowired
	private AgencyLevelMapper agencyLevelMapper;
	
	@Override
	protected <T extends BaseEntity> BaseMapper getBaseMapper() {
		return agencyLevelMapper;
	}
	
	@Override
	public <T extends BaseEntity> T find(long id) {
		return (T) agencyLevelMapper.selectByPrimaryKey(id);
	}

	@Override
	public void findList(PageUtils pageinfo) {
		long total = agencyLevelMapper.filterCount(pageinfo.getCondition());
		pageinfo.setTotal(total);
		if(total > 0) {
			pageinfo.setData(agencyLevelMapper.findList(pageinfo));
		} else {
			pageinfo.setData(new ArrayList<AgencyLevelEntity>());
		}
	}

	@Override
	public List<Select> findBySelect(Long facId) {
		return agencyLevelMapper.selectLevelByFacId(facId);
	}
	
	@Override
	public List<Select> selectListBySelect(Long facId, String filter) {
		return agencyLevelMapper.selectListBySelect(facId, filter);
	}

	@Override
	@Transactional
	public boolean deletes(Long userId, Long facId, Long[] ids) {
		return agencyLevelMapper.updateStatus(userId, facId, ids, -1) > 0 ? true : false;
	}

	@Override
	public boolean verifyUniquely(Long id, Long facId, String name) {
		return agencyLevelMapper.verifyUniquely(id, facId, name) > 0 ? false : true;
	}

	@Override
	public Long selectId(String str, Long facId) {
		
		return agencyLevelMapper.selectId(str, facId);
	}

}
